package com.ruoyi.fly.service.impl;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.fly.domain.Notice;
import com.ruoyi.fly.domain.vo.NoticeVo;
import com.ruoyi.fly.mapper.NoticeMapper;
import com.ruoyi.fly.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    /**
     * 根据id查询公告
     *
     * @param id
     * @return
     */
    @Override
    public Notice selectNoticeById(String id) {
        return noticeMapper.selectNoticeById(id);
    }

    /**
     * 查询公告列表
     *
     * @param notice
     * @return
     */
    @Override
    public List<Notice> selectNoticeList(Notice notice) {
        return noticeMapper.selectNoticeList(notice);
    }

    /**
     * 新增公告
     *
     * @param noticeVo
     * @return
     */
    @Override
    public R insertNotice(NoticeVo noticeVo) {
        noticeVo.setCreateTime(DateUtils.getNowDate());
        noticeVo.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return noticeMapper.insertNotice(noticeVo) > 0 ? R.ok("新增成功") : R.fail("操作失败");
    }

    /**
     * 修改公告
     *
     * @param noticeVo
     * @return
     */
    @Override
    public R updateNotice(NoticeVo noticeVo) {
        noticeVo.setUpdateTime(DateUtils.getNowDate());
        noticeVo.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        return noticeMapper.updateNotice(noticeVo) > 0 ? R.ok("修改成功") : R.fail("操作失败");
    }

    @Override
    public R deleteNoticeById(String id) {
        return noticeMapper.deleteNoticeById(id) > 0 ? R.ok("删除成功") : R.fail("操作失败");
    }

    @Override
    public R deleteNoticeByIds(String[] ids) {
        return noticeMapper.deleteNoticeByIds(ids) > 0 ? R.ok("删除成功") : R.fail("操作失败");
    }
}
